package com.designPatterns.singleton;

/**
 * 单例模式:立即加载的一个变种
 * 同样基于类的加载机制,避免了线程同步问题,不过是放到了静态块中
 * Created by houjinxin on 16/3/5.
 */
public class SingletonInstantLoadVariant {

    private static SingletonInstantLoadVariant instance = null;

    static {
        instance = new SingletonInstantLoadVariant();
    }

    private SingletonInstantLoadVariant(){
        System.out.println("我是即时加载的变种类");
    }

    public static SingletonInstantLoadVariant getInstance(){
        return instance;
    }

    /**
     * 该方法用于测试即使未getInsance 实例也会被创建
     */
    public static void doSomething(){
        System.out.println("干了一些事情");
    }
}
